package Hot100;

import java.util.Stack;

public class 最小栈 {
    class MinStack {

        private Stack<Integer> stack;
        private Stack<Integer> minStack;

        public MinStack() {
            stack = new Stack<>();
            minStack = new Stack<>();
        }

        public void push(int val) {
            stack.push(val);
            if (minStack.isEmpty()) minStack.push(val);
            else if (val <= minStack.peek()) minStack.push(val);
        }

        public void pop() {
            Integer num = stack.pop();
            if (minStack.peek().equals(num)) minStack.pop();
        }

        public int top() {
            return stack.peek();
        }

        public int getMin() {
            return minStack.peek();
        }
    }
}
